## 1. 导入 pip install openai i https://pypi.tuna.tsinghua.edu.cn/simple
import os
from openai import OpenAI  # pip install openai -i https://pypi.tuna.tsinghua.edu.cn/simple
from dotenv import load_dotenv  # pip install python-dotenv -i https://pypi.tuna.tsinghua.edu.cn/simple

load_dotenv()  # 加载配置好的环境变量
# client = OpenAI(api_key="sk-1ec4f2d5fa8f4fd7b031567e2839d067",
#                base_url="https://dashscope.aliyuncs.com/compatible-mode/v1") ## 写死的调用方法

client = OpenAI()  # 初始化 client 客户端
response = client.chat.completions.create(
    model="qwen-plus",
    messages=[{"role": "user", "content": "你好"}])
print(response.choices[0].message.content)

# 获取模型列表
models = client.models.list()
print(models)

for model in models.data:
    print(model.id)
